<?php
/**
 * Tags
 */
include LIB_PATH . '/YAction.class.php';
class TagsAction extends YAction {
	public function __construct() {
		parent::__construct();
		
		// 登录检测
		if(!$this->isLogin()) {
			echo '_error Access Timeout'; exit;
		}
	}
	
	// 列表
	public function index() {
		$data = D('Tags')->getListByPage();
		$pageString = $data['pageString'];
		unset($data['pageString']);
		$this->assign('data', $data);
		
		$this->display();
	}
	
	// 添加
	public function addTag() {
		$this->display();
	}
	public function doAddTag() {
		$data = array();
		$data['tagname'] = y_getParam('tagname');
		
		D('Tags')->addOne($data);
		
		$this->success('添加成功');
	}
	
	// 修改
	public function editTag() {
		$id = y_getParam('id', 'get');
		if(!is_numeric($id)) {
			$this->error('参数错误');
			exit;
		}
		
		$data = D('Tags')->getOneByPk($id);
		$this->assign('data', $data);
		
		$this->display();
	}
	public function doEditTag() {
		$id = y_getParam('pkid');
		$data = array();
		if(!is_numeric($id)) {
			$this->error('参数错误');
			exit;
		}
		
		$data['tagname'] = y_getParam('tagname');
		D('Tags')->updateOne('id='.$id, $data);
		
		$this->success('修改成功');
	}
	
	// 删除
	public function delTag() {
		$id = y_getParam('id', 'get');
		if(!is_numeric($id)) {
			$this->error('参数错误');
			exit;
		}
		
		D('Tags')->deleteOne('id='.$id);
		
		$this->success('删除成功');
	}
}